import { RouteRecordRaw } from 'vue-router';

const modules = import.meta.glob('./modules/**/*.ts', { eager: true });

function formatRoutes(modules: Record<string, any>): RouteRecordRaw[] {
  return Object.values(modules).reduce((routes: RouteRecordRaw[], module) => {
    const moduleRoutes = module.default?.routes || module.default;
    if (Array.isArray(moduleRoutes)) {
      routes.push(...moduleRoutes);
    }
    return routes;
  }, []);
}

const routes = formatRoutes(modules);

export default routes;
